﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DPS.Prototype.Provider.Interface;
using DPS.Prototype.Model;
using DPS.DataModel;
using System.Configuration;
namespace DPS.Prototype.Provider
{
    public class CapacityProvider:ICapacityProvider
    {
      //  private static string dataConnString = ConfigurationManager.ConnectionStrings["DPSConnectionString"].ConnectionString;
       
        public List<Capacity> GetCapacityByProdline(ProdLine prodLine)
        {
            List<Capacity> capacitys = new List<Capacity>();

            DPSDataModelDataContext dataContext = DataContextProvider.DataContext;
            var query = dataContext.DPSBatchTs.Where(batch => batch.BatchType == "UPH" && batch.Status == "1").Select(b => b.BatchID);
            if (query.Count() > 0)
            {
                string batchId = query.First();
                List<DPSUPHByBatchT> list = dataContext.DPSUPHByBatchTs.Where(uph => uph.BatchID == batchId && uph.ProdLine == prodLine.LineNo).ToList();
                list.ForEach(u => {
                    Capacity capacity = Model.Adapter.CapacityAdapter.Adapter(u);
                    capacity.ProdLine = prodLine;
                    capacitys.Add(capacity);
                });
            }
            return capacitys;
        }
    }
}
